package org.mozilla.intl.chardet;

import java.io.BufferedInputStream;
import java.net.URL;

public class HtmlCharsetDetector
{
  public static boolean found = false;

  public static void main(String[] paramArrayOfString)
    throws Exception
  {
    if ((paramArrayOfString.length != 1) && (paramArrayOfString.length != 2))
    {
      System.out.println("Usage: HtmlCharsetDetector <url> [<languageHint>]");
      System.out.println("");
      System.out.println("Where <url> is http://...");
      System.out.println("For optional <languageHint>. Use following...");
      System.out.println("\t\t1 => Japanese");
      System.out.println("\t\t2 => Chinese");
      System.out.println("\t\t3 => Simplified Chinese");
      System.out.println("\t\t4 => Traditional Chinese");
      System.out.println("\t\t5 => Korean");
      System.out.println("\t\t6 => Dont know (default)");
      return;
    }
    int i = paramArrayOfString.length == 2 ? Integer.parseInt(paramArrayOfString[1]) : 0;
    nsDetector localnsDetector = new nsDetector(i);
    localnsDetector.Init(new nsICharsetDetectionObserver()
    {
      public void Notify(String paramAnonymousString)
      {
        HtmlCharsetDetector.found = true;
        System.out.println("CHARSET = " + paramAnonymousString);
      }
    });
    URL localURL = new URL(paramArrayOfString[0]);
    BufferedInputStream localBufferedInputStream = new BufferedInputStream(localURL.openStream());
    byte[] arrayOfByte = new byte[1024];
    boolean bool1 = false;
    boolean bool2 = true;
    int j;
    while ((j = localBufferedInputStream.read(arrayOfByte, 0, arrayOfByte.length)) != -1)
    {
      if (bool2)
        bool2 = localnsDetector.isAscii(arrayOfByte, j);
      if ((!bool2) && (!bool1))
        bool1 = localnsDetector.DoIt(arrayOfByte, j, false);
    }
    localnsDetector.DataEnd();
    if (bool2)
    {
      System.out.println("CHARSET = ASCII");
      found = true;
    }
    if (!found)
    {
      String[] arrayOfString = localnsDetector.getProbableCharsets();
      for (int k = 0; k < arrayOfString.length; k++)
        System.out.println("Probable Charset = " + arrayOfString[k]);
    }
  }
}

/* Location:           D:\soft\chardet.jar
 * Qualified Name:     org.mozilla.intl.chardet.HtmlCharsetDetector
 * JD-Core Version:    0.6.1
 */